import type { AxiosRequestConfig } from '@vben/request';

import type { DefApplicationModel } from './model/defApplicationModel';

import type { PageParams, PageResult } from '#/api';

import { requestClient } from '#/api/request';
import { ServicePrefixEnum } from '#/enums/commonEnum';

const MODULAR = 'defApplication';

export const DefApplicationConfig = {
  Save: {
    url: `${ServicePrefixEnum.SYSTEM}/${MODULAR}`,
    method: 'POST',
  } as AxiosRequestConfig,
  Update: {
    url: `${ServicePrefixEnum.SYSTEM}/${MODULAR}`,
    method: 'PUT',
  } as AxiosRequestConfig,
};

export namespace DefApplicationApi {
  export async function findApplicationResourceList() {
    return requestClient.get<DefApplicationModel.ApplicationResourceResultVO[]>(
      `${ServicePrefixEnum.SYSTEM}/${MODULAR}/findApplicationResourceList`,
    );
  }
  export async function findAvailableApplicationResourceList() {
    return requestClient.get<DefApplicationModel.ApplicationResourceResultVO[]>(
      `${ServicePrefixEnum.SYSTEM}/${MODULAR}/findAvailableApplicationResourceList`,
    );
  }
  export async function findAvailableApplicationDataScopeList() {
    return requestClient.get<DefApplicationModel.ApplicationResourceResultVO[]>(
      `${ServicePrefixEnum.SYSTEM}/${MODULAR}/findAvailableApplicationDataScopeList`,
    );
  }

  /**
   * 分页查询
   */
  export async function page(
    params: PageParams<DefApplicationModel.DefApplicationPageQuery>,
  ) {
    return requestClient.post<
      PageResult<DefApplicationModel.DefApplicationResultVO>
    >(`${ServicePrefixEnum.SYSTEM}/${MODULAR}/page`, params);
  }

  export async function query(
    params?: DefApplicationModel.DefApplicationPageQuery,
  ) {
    return requestClient.post<DefApplicationModel.DefApplicationResultVO[]>(
      `${ServicePrefixEnum.SYSTEM}/${MODULAR}/query`,
      params,
    );
  }

  export async function save(params: DefApplicationModel.DefApplicationSaveVO) {
    return requestClient.post<DefApplicationModel.DefApplicationResultVO>(
      DefApplicationConfig.Save.url as string,
      params,
    );
  }

  export async function update(
    params: DefApplicationModel.DefApplicationUpdateVO,
  ) {
    return requestClient.put<DefApplicationModel.DefApplicationResultVO>(
      DefApplicationConfig.Update.url as string,
      params,
    );
  }
  export async function remove(data: string[]) {
    return requestClient.delete<boolean>(
      `${ServicePrefixEnum.SYSTEM}/${MODULAR}`,
      { data },
    );
  }
}

/** 查询我的应用 */
export async function findMyApplication(
  params: DefApplicationModel.DefApplicationPageQuery,
) {
  return requestClient.get<DefApplicationModel.DefApplicationResultVO[]>(
    `${ServicePrefixEnum.SYSTEM}/anyone/findMyApplication`,
    { params },
  );
}
export async function findRecommendApplication(
  params: DefApplicationModel.DefApplicationPageQuery,
) {
  return requestClient.get<DefApplicationModel.DefApplicationResultVO[]>(
    `${ServicePrefixEnum.SYSTEM}/anyone/findRecommendApplication`,
    { params },
  );
}
